Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

http-terminator

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

http-terminator

Gracefully terminates HTTP(S) server.

  • 2.0.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
784K
decreased by-4.17%
Maintainers
1
Weekly downloads
 
Created

What is http-terminator?

The http-terminator npm package provides a reliable way to gracefully terminate HTTP and HTTPS servers. It ensures that all active connections are properly closed before the server shuts down, preventing potential data loss or corruption.

What are http-terminator's main functionalities?

Graceful Server Termination

This feature allows you to gracefully terminate an HTTP server, ensuring that all active connections are properly closed before the server shuts down.

const { createHttpTerminator } = require('http-terminator');
const http = require('http');

const server = http.createServer((req, res) => {
  res.end('Hello, world!');
});

server.listen(3000);

const httpTerminator = createHttpTerminator({ server });

// To terminate the server gracefully
httpTerminator.terminate().then(() => {
  console.log('Server terminated');
});

Handling Long-Lived Connections

This feature demonstrates how http-terminator handles long-lived connections, ensuring they are properly closed before the server shuts down.

const { createHttpTerminator } = require('http-terminator');
const http = require('http');

const server = http.createServer((req, res) => {
  setTimeout(() => {
    res.end('Delayed response');
  }, 10000); // Simulate a long-lived connection
});

server.listen(3000);

const httpTerminator = createHttpTerminator({ server });

// To terminate the server gracefully
httpTerminator.terminate().then(() => {
  console.log('Server terminated');
});

Custom Termination Timeout

This feature allows you to set a custom timeout for graceful termination, giving you control over how long the server should wait before forcefully closing connections.

const { createHttpTerminator } = require('http-terminator');
const http = require('http');

const server = http.createServer((req, res) => {
  res.end('Hello, world!');
});

server.listen(3000);

const httpTerminator = createHttpTerminator({
  server,
  gracefulTerminationTimeout: 5000 // Custom timeout in milliseconds
});

// To terminate the server gracefully
httpTerminator.terminate().then(() => {
  console.log('Server terminated');
});

Other packages similar to http-terminator

Keywords

FAQs

Package last updated on 19 Apr 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc